/* 
  Copyright (c) SilverLining 2015
  Date:    2016-1-7
  File:    shim_object.h  
  Description: 

*/

#pragma once

namespace SL
{
	namespace M
	{
		ref class GameObject;

		typedef void(__stdcall *ObjectWriteCallback)(m::archiver* archiver);
		typedef void(__stdcall *ObjectReadCallback)(m::archiver* archiver);

		/// <summary>
		/// Represent a native shim for managed game objects.
		/// </summary>
		/// <remarks>This class is meant for internal use.</remarks>
		class shim_object : public m::object
		{
		public:
			shim_object();
			~shim_object();

			/// <summary>
			/// Initialize the object.
			/// </summary>
			/// <param name="obj">The managed object to be used for initialization.</param>
			void set_object(GameObject^ obj);
				
			/// <summary>
			/// Return the object being shimmed.
			/// </summary>
			/// <returns>A game object.</returns>
			GameObject^ get_object();

			virtual std::wstring to_string() const;

			void * operator new(size_t sz);
			void operator delete(void * ptr);

		protected:
			virtual void read(m::archiver* archiver);
			virtual void write(m::archiver* archiver);

		private:
			ObjectWriteCallback WriteCallback;
			ObjectReadCallback ReadCallback;

			wchar_t* TypeName;
			void* _hObject;

		};
	}
}